package com.feel.controller;

import com.feel.pojo.RespBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @Author: 刘永钦
 * @Date: 2024-08-30-11:37
 * @Description:
 */
@RestController
@RequestMapping("/admin")
public class FileController {
    @Value("${images.path}")
    private String basePath;

    @PostMapping("/upload")
    public RespBean upload(MultipartFile file) throws IOException {
        String name = file.getOriginalFilename();
        // todo 可以进行其他方式重命名
        String new_name = UUID.randomUUID().toString().replace("-", "") + "_" + name;

        file.transferTo(new File(basePath + new_name));
        return RespBean.ok("上传成功", new_name);
    }
}
